home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
FontMancer
/
CDEF
/
Sources
/
cdef.c
< prev
Wrap
C/C++ Source or Header
|
1996-06-21
|
2KB
|
96 lines
//with Hints from ICONDef.c in MPW examples
#ifndef __CONTROLS__
#include <Controls.h>
#endif
#ifndef __FONTS__
#include <Fonts.h>
#endif
#ifndef __MEMORY__
#include <Memory.h>
#endif
#ifndef __TOOLUTILS__
#include <ToolUtils.h>
#endif
extern struct picStorage {
long buttonHilite;
PicHandle buttonNormal;
PicHandle buttonPressed;
PicHandle buttonInactUp;
PicHandle buttonInactDown;
};
pascal long main(short varCode, ControlHandle ctl, short msg, long parm);
pascal long main(short varCode, ControlHandle ctl, short msg, long parm)
{
struct picStorage *buttonPic;
Point cursorLoc;
short cHilite,cValue;
HLock((Handle) ctl);
buttonPic = (struct picStorage *) (**ctl).contrlRfCon;
cHilite = (**ctl).contrlHilite;
cValue = (**ctl).contrlValue;
if (StillDown() && (cHilite != 255)) buttonPic->buttonHilite = cHilite;
switch (msg) {
case drawCntl:
switch (varCode & (short)0xFFF7) {
case 0:
case 1:
case 2:
if (!buttonPic) {
HUnlock((Handle) ctl);
return(0);
}
if (cHilite == 255) {
if (cValue)
DrawPicture(buttonPic->buttonInactDown,&(**ctl).contrlRect);
else
DrawPicture(buttonPic->buttonInactUp,&(**ctl).contrlRect);
break;
}
if (((buttonPic->buttonHilite) && cValue) || ((!buttonPic->buttonHilite) && !cValue))
DrawPicture(buttonPic->buttonNormal,&(**ctl).contrlRect);
else
DrawPicture(buttonPic->buttonPressed,&(**ctl).contrlRect);
break;
case 3:
EraseRect(&(**ctl).contrlRect);
break;
}
break;
case testCntl:
SetPt(&cursorLoc,LoWord(parm),HiWord(parm));
if (PtInRect(cursorLoc,&((**ctl).contrlRect))) return(1);
else return(0);
break;
case calcCRgns:
case calcCntlRgn:
if (msg == calcCRgns)
parm &= 0x00FFFFFF;
RectRgn((RgnHandle)parm, &(**ctl).contrlRect);
break;
case initCntl:
case dispCntl:
case posCntl:
case thumbCntl:
case dragCntl:
case autoTrack:
break;
}
if (!Button() && (cHilite !=255)) buttonPic->buttonHilite = cHilite;
HUnlock((Handle) ctl);
return(0);
}